import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Solution1106 {

    int pre=0;
    Stack<Character> stack=new Stack<>();

    public boolean parseBoolExpr(String expression) {
        if (expression.charAt(pre)=='f'){
            pre++;
            return false;
        }else if (expression.charAt(pre)=='t'){
            pre++;
            return true;
        }else if (expression.charAt(pre)=='!'){
            pre++;
            stack.push('!');
            return parseBoolExpr(expression);
        }else if (expression.charAt(pre)=='&'){
            pre++;
            stack.push('&');
            return parseBoolExpr(expression);
        }else if (expression.charAt(pre)=='|'){
            pre++;
            stack.push('|');
            return parseBoolExpr(expression);
        }else if (expression.charAt(pre)=='('){
            pre++;
            List<Boolean> list=new ArrayList<>();
            while (expression.charAt(pre)!=')'){
                if  (expression.charAt(pre)=='f'){
                    list.add(false);
                }else if (expression.charAt(pre)=='t'){
                    list.add(true);
                }else if (expression.charAt(pre)!=',') {
                    list.add(parseBoolExpr(expression));
                    pre--;
                }
                pre++;
            }
            pre++;
            Character character=stack.pop();
            if (character=='!'){
                return !list.get(0);
            }else if (character=='&'){
                boolean ans=list.get(0);
                for (int i=1;i<list.size();i++){
                    ans=ans&list.get(i);
                }
                return ans;
            }else if (character=='|'){
                boolean ans=list.get(0);
                for (int i=1;i<list.size();i++){
                    ans=ans|list.get(i);
                }
                return ans;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1106().parseBoolExpr("|(&(t,f,t),!(t))"));
    }
}
